<?php

/**
 * Description of elFinderVolumeFileSystemMappedMySQL
 * Extiende las funcionalidades de elFinderVolumeMySQL para adaptarlas al Generador
 * modificando aquellos métodos que acceden a la base de datos.
 * 
 * @author Diego
 */
class elFinderVolumeFileSystemMappedMySQL extends elFinderVolumeMySQL {

    /**
     * Create empty object with required mimetype
     *
     * @param  string  $path  parent dir path
     * @param  string  $name  object name
     * @param  string  $mime  mime type
     * @return bool
     * @author Dmitry (dio) Levashov
     * */
    protected function make($path, $name, $mime) {

        echo "<b> Entra </b><br>";
        $sql = 'INSERT INTO gen_multimedia_categoria SET
      nombre = "%s",
      id_padre = %d,
      lectura = %d,
      escritura = %d,
      mime = "%s"
      ';
        $sql = sprintf($sql, $this->db->real_escape_string($name), $path, $this->defaults['read'], $this->defaults['write'], $mime
        );
        //$sql = 'INSERT INTO %s (`parent_id`, `name`, `size`, `mtime`, `mime`, `content`, `read`, `write`) VALUES ("%s", "%s", 0, %d, "%s", "", "%d", "%d")';
        //$sql = sprintf($sql, $this->tbf, $path, $this->db->real_escape_string($name), time(), $mime, $this->defaults['read'], $this->defaults['write']);
        //echo $sql;
        return $this->query($sql) && $this->db->affected_rows > 0;
    }
    
        
    /**
	 * Join dir name and file name and return full path
	 *
	 * @param  string  $dir
	 * @param  string  $name
	 * @return string
	 * @author Dmitry (dio) Levashov
	 **/
	protected function _joinPath($dir, $name) {
            echo "<pre>";
            var_dump(debug_backtrace());
            echo "<pre>"; 
		$sql = 'SELECT id FROM gen_multimedia_categoria 
                    WHERE id_padre = '.$dir.'
                    AND nombre = "'.$this->db->real_escape_string($name).'"';

                echo $sql ."<br>";
		if (($res = $this->query($sql)) && ($r = $res->fetch_assoc())) {
			$this->updateCache($r['id'], $this->_stat($r['id']));
                        echo "ok <br>";
                        return $r['id'];
		}
                echo "fail <br>";
		return -1;
	}

}

?>
